﻿using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication
{
    public class StubCustomerRepository : ICustomerRepository
    {
        private readonly IList<Customer> _customers = new List<Customer>();

        public StubCustomerRepository()
        {
            _customers = new List<Customer>
                             {
                                 new Customer
                                     {
                                         Id = 1,
                                         Name = "ThangChung",
                                         Gender = false,
                                         Address = "SE10 0RU"
                                     },
                                 new Customer
                                     {
                                         Id = 2,
                                         Name = "CR7",
                                         Gender = true,
                                         Address = "Somewhere"
                                     }
                             };
        }

        public IEnumerable<Customer> GetAll()
        {
            return _customers;
        }

        public Customer Get(int id)
        {
            return _customers.FirstOrDefault(x => x.Id == id);
        }

        public int Add(Customer c)
        {
            _customers.Add(c);

            return 1;
        }

        public int Update(Customer c)
        {
            var customer = _customers.FirstOrDefault(x => x.Id == c.Id);
            _customers.Remove(customer);
            _customers.Add(c);

            return 1;
        }

        public int Delete(Customer c)
        {
            _customers.Remove(c);

            return 1;
        }
    }
}